package com.example.demo.controller;

import com.example.demo.entity.Account;
import com.example.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/account")
public class AccountController implements BaseController<Account>{
    @Autowired
    AccountService accountService;

    @GetMapping("/{id}")
    public Account findByID(@PathVariable  int id) {
        return accountService.findByID(id);
    }

    @GetMapping("/")
    public List<Account> findAll() {
        return accountService.findAll();
    }

    @PostMapping("")
    public Account save(@RequestBody  Account account) {
        return accountService.save(account);
    }

    @DeleteMapping("/{id}")
    public boolean deleteByid(@PathVariable  int id) {
        return accountService.deleteByid(id);
    }

    @PutMapping("")
    public Account updateById(@RequestBody  Account account) {
        Account account1 = accountService.updateById(account);
        return account1;
    }

    @GetMapping("/findAllByPage/{pageNum}")
    public Page<Account> findAllByPage(@PathVariable  int pageNum) {
        Page<Account> allByPage = accountService.findAllByPage(--pageNum);
        return allByPage;
    }
    @GetMapping("findAllByCustomer_CustomerId/{id}")
    public List<Account> findAllByCustomer_CustomerId(@PathVariable  int id){
        List<Account> allByCustomer_customerId = accountService.findAllByCustomer_CustomerId(id);
        return allByCustomer_customerId;
    }
}
